#include <stdlib.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

#include "file.h"

// micro function (don't print "doing X..." status)
// removes error checking boilerplate
void write_file(const char *filename, const char *buf, size_t buflen)
{
    int fd;

    fd = open(filename, O_RDWR | O_CREAT, 0755);
    if (fd < 0)
    {
        perror("open$write_file");
        exit(1);
    }

    if (write(fd, buf, buflen) != buflen)
    {
        perror("write$write_file");
        exit(1);
    }

    close(fd);
}